import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ConfigurationService } from './services/configuration.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
import { UserService } from './services/user.service';
@Global() // 全局模块
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigurationService],
      useFactory: (ConfigurationService: ConfigurationService) => ({
        type: 'mysql', // 连接数据库的类型
        ...ConfigurationService.mysqlConfig,
        autoLoadEntities: true, // 自动加载实体
        synchronize: true, // 保持代码和数据库结构一致
        logging: true, // 打印sql语句
      }),
    }),
    TypeOrmModule.forFeature([User]),
  ], //全局引入ConfigModule模块
  providers: [ConfigurationService, UserService],
  exports: [ConfigurationService, UserService],
})
export class SharedModule {}
